package com.example.boot.order.service.impl;

import java.util.Date;
import java.util.UUID;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.boot.ResultEnum.ResultEnum;
import com.example.boot.exception.BootException;
import com.example.boot.order.dao.OrderDao;
import com.example.boot.order.model.Order;
import com.example.boot.order.service.OrderService;

@Service
public class OrderImpl implements OrderService {
	@Autowired
	private OrderDao orderDao;

//	@Autowired
//	private RedisUtil redisUtil;

	public Order selectByPrimaryKey(String id) {

		return orderDao.selectByPrimaryKey(id);
	}

	@Override
	@Transactional // 该注解就是
	public int insertSelective() throws Exception {

		String id = UUID.randomUUID().toString().replace("-", "");
		Order o = new Order();
		o.setCreateDate(new Date());
		o.setDeleteStatus(0);
		o.setId(id);
		o.setNumber(0);
		o.setNumberPrice(0.5);
		o.setOdds(0.1);
		o.setOpenId("dsajiodsaj");
		o.setOrderId("02c34de31754498eaa7208eeeed50b91");
		// int insert2 = orderDao.insert(o);
		// System.out.println(("o: " + insert2));

		// Order o1 = new Order();
		// o1.setCreateDate(new Date());
		// o1.setDeleteStatus(0);
		// o1.setId(id);
		// o1.setNumber(0);
		// o1.setNumberPrice(0.5);
		// o1.setOdds(0.1);
		// o1.setOpenId("dsajiodsaj");
		// o1.setOrderId("02c34de31754498eaa7208eeeed50b91");
		// int insert = orderDao.insert(o1);
		// System.out.println(("o1: "+insert));
		// int deleteByPrimaryKey = 
		// orderDao.deleteByPrimaryKey("029a8745eaed4617b3cec1c758815f98");
		// System.out.println("delete " + deleteByPrimaryKey);
		return 0;
	}

	@Override
	public Object get(String key, String value) {
//		Object object = redisUtil.set(key, value);
//		Boolean b = (Boolean) object;
//		if (b) {
//			return redisUtil.get(key);
//		}

		throw new BootException(ResultEnum.NEVER_KEY);
	}

}
